home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 620 < prev    next >
Internet Message Format  |  1996-08-06  |  1KB

  1. Path: usin.com!rwells
  2. From: rwells@usin.com (Roger Wells)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Restrictions on qsort compare function?
  5. Date: 21 Mar 1996 17:00:46 GMT
  6. Organization: U.S. Intelco Networks, Inc.
  7. Distribution: world
  8. Message-ID: <4is1vu$5et@news1.halcyon.com>
  9. References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com>
  10. NNTP-Posting-Host: 198.202.216.7
  11.  
  12. In article <4iqjar$2m9@usenet.pa.dec.com>, diamond@tbj.dec.com (Norman Diamond) writes:
  13. >In article <4iokop$h4p@lyra.csx.cam.ac.uk>, jkb@mrc-lmb.cam.ac.uk (James Bonfield) writes:
  14. >>Are there any limitations on what the sort function passed over to qsort can
  15. >>do or return?
  16. >
  17. >>I know it's meant to return < 0, 0 or > 0 for the various compare operations,
  18. >>but which you return is purely up to your own comparison system.
  19. >
  20. >Exactly.
  21. >
  22. >>On tracking down a bug in some old code I noticed that we had the
  23. >>compare function returning something like "a > b" instead of "b - a".
  24. >>Now this is obviously some silly bug in our coding,
  25. >
  26. >Actually it's a silly question.  Just one sentence earlier, you gave the
  27. >exact reason why it doesn't matter if you do "a > b" instead of "a - b".
  28.  
  29. The expression a > b can only have the values 0 or 1; therefore, if your
  30. qsort comparison returns a > b it will never return a negative value.  If
  31. a is less than b, it will return 0, which to qsort means they are equal.  I
  32. do not believe that is what you want.
  33.  
  34. --
  35. Roger Wells (speaking only for myself)
  36.